home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / comm2 / amislt14.lha / AmiSlate / SlateRexx / Mandelbrot.rexx < prev    next >
OS/2 REXX Batch file  |  1996-01-27  |  4KB  |  156 lines

  1. /* An Arexx script for use with AmiSlate:  
  2.  
  3.   Mandelbrot generator for AmiSlate.
  4.  
  5.   Copyright (c) 1995,1996 Johan Torin  (johan@artworks.apana.org.au)
  6.  
  7.   Minor enhancements by Jeremy Friesner (jfriesne@ucsd.edu)
  8.   
  9. */
  10.  
  11. parse arg CommandPort ActiveString
  12.  
  13. address (CommandPort)
  14.  
  15. if (length(CommandPort) == 0) then do
  16.     say ""
  17.     say "Usage:  rx mandelbrot.rexx <REXXPORTNAME>"
  18.     say "        (REXXPORTNAME is usually AMISLATE)"
  19.     say ""
  20.     say "Or run from the Rexx menu within AmiSlate."
  21.     say ""
  22.     exit 0
  23.     end
  24.  
  25. options results
  26.  
  27. /* Calculate size of drawing area */
  28. GetWindowAttrs stem win.
  29. X_Size = trunc((win.width-58))
  30. Y_Size = trunc((win.height-53))
  31. Num_Colors = 2 ** win.depth
  32.  
  33. /* Set colors, if the user wants */
  34. EasyRequest "Mandelbrot" '"'||"Do you want to use the Mandelbrot palette?"||'"' "Yes|No"
  35.  
  36. /* Get object */
  37. if (rc == 1) then do
  38.     SetPenColor 0 0 0 0
  39.     SetPenColor 1 0 0 15
  40.     SetPenColor 2 2 2 15
  41.     SetPenColor 3 4 4 15
  42.     SetPenColor 4 6 6 15
  43.     SetPenColor 5 8 8 15
  44.     SetPenColor 6 10 10 15
  45.     SetPenColor 7 12 12 15
  46.     SetPenColor 8 14 14 15
  47.     SetPenColor 9 15 15 15
  48.     SetPenColor 10 15 15 10
  49.     SetPenColor 11 15 15 5
  50.     SetPenColor 12 15 15 0
  51.     SetPenColor 13 15 13 0
  52.     SetPenColor 14 15 12 0
  53.     SetPenColor 15 15 11 0
  54.     SetPenColor 16 15 9 0
  55.     SetPenColor 17 15 8 0
  56.     SetPenColor 18 15 7 0
  57.     SetPenColor 19 15 6 0
  58.     SetPenColor 20 15 4 0
  59.     SetPenColor 21 15 3 0
  60.     SetPenColor 22 15 2 0
  61.     SetPenColor 23 15 0 0
  62.     SetPenColor 24 13 0 2
  63.     SetPenColor 25 12 0 4
  64.     SetPenColor 26 10 0 6
  65.     SetPenColor 27 9 0 8
  66.     SetPenColor 28 7 0 10
  67.     SetPenColor 29 6 0 12
  68.     SetPenColor 30 4 0 14
  69.     SetPenColor 31 2 0 15
  70.     end
  71.  
  72. /* Init some variables */
  73. PixelSize = 4                         /* The size of each dot in pixels */
  74.  
  75. /* Set this to SOLID, MOSAIC, TILE_BUBBLES, or OVERLAP_BUBBLES for different effects */
  76. Effect = SOLID
  77.  
  78. /* Higher = slower & prettier, lower = faster */
  79. Iterations = 32
  80.  
  81. /* Figure out which pen is black now, as it's expensive to do */
  82. SetUserFColor 0 0 0
  83. GetStateAttrs stem state.
  84. blackpen = state.fpen
  85.  
  86. Z_r = 0
  87. Z_i = 0
  88. C_r = 0
  89. C_i = 0
  90. K_r = 0
  91. K_i = 0
  92. Delta_r = 0
  93. Delta_i = 0
  94. Itt = 0
  95. X = 0
  96. Y = 0
  97.  
  98. Start_r = -2.5
  99. Start_i = -1.75
  100. End_r = 1.5
  101. End_i = 1.75
  102.  
  103. Ul_r = Start_r
  104. Ul_i = Start_i
  105. Lr_r = End_r
  106. Lr_i = End_i
  107.  
  108. Delta_r = Lr_r-Ul_r
  109. Delta_i = Lr_i-Ul_r
  110.  
  111. /* Since PixelSize is actually the height of the square... */
  112. PixelSize = PixelSize - 1
  113.  
  114. Do Y = 0 to Y_Size-1 BY PixelSize+1
  115.    C_i = Delta_i/Y_Size*Y+Ul_i
  116.    Do X = 0 to X_Size-1 BY PixelSize+1
  117.       C_r = Delta_r/X_Size*X+Ul_r
  118.       Z_r = C_r
  119.       Z_i = C_i
  120.       K_r = Z_r * Z_r
  121.       K_i = Z_i * Z_i
  122.       Itt = 0
  123.       Do While ((K_r + K_i) < 4) & (Itt < Iterations)
  124.          Z_i = 2 * Z_r * Z_i + C_i
  125.          Z_r = K_r - K_i + C_r
  126.          K_r = Z_r * Z_r
  127.          K_i = Z_i * Z_i
  128.          Itt = Itt + 1
  129.          end
  130.       If Itt > Iterations-2 then Itt = -3     /* Kludge. */
  131.       
  132.       if (Effect == SOLID) then do
  133.           SetFPen Itt+4
  134.           Square X Y X+PixelSize Y+PixelSize FILL
  135.           end
  136.       else if (Effect == MOSAIC) then do
  137.           SetFPen Itt+4
  138.           Square X Y X+PixelSize Y+PixelSize FILL
  139.           SetFPen BlackPen
  140.           Square X Y X+PixelSize Y+PixelSize 
  141.           end                           
  142.       else if (Effect == OVERLAP_BUBBLES) then do
  143.           SetFPen Itt+4
  144.           Circle X Y PixelSize PixelSize FILL
  145.           SetFPen BlackPen
  146.           Circle X Y PixelSize PixelSize
  147.           end
  148.       else if (Effect == TILE_BUBBLES) then do
  149.           SetFPen Itt+4
  150.           Circle X Y PixelSize%2 PixelSize%2 FILL
  151.           SetFPen BlackPen
  152.           Circle X Y PixelSize%2 PixelSize%2
  153.           end
  154.    End
  155. End
  156.